print("---------- typeof ----------")
class MedeiaItem {
    var name: String
    init(name: String) {
        self.name = name
    }
}

class Movie: MedeiaItem {
    var director: String
    init(name: String, director: String) {
        self.director = director
        super.init(name: name)
    }
}

class Song: MedeiaItem {
    var artist: String
    init(name: String, artist: String) {
        self.artist = artist
        super.init(name: name)
    }
}

let library = [
    Movie(name: "King of the Jungle", director: "Webster Cullison"),
    Song(name: "Lemmon tree", artist: "Joanna wang"),
]
print(type(of: library))
print(type(of: 8))
print(type(of: 8.0))
print(type(of: false))

print("---------- is和as ----------")
for item in library {
    // 写法1
    if (item is Movie) {
        let realItem = item as! Movie
        print("电影\(realItem.name)的导演是: \(realItem.director)")
        continue
    }
    
    // 写法2
    if let realItem = item as? Song {
        print("歌曲\(realItem.name)的作者是: \(realItem.artist)")
    }
}
